package com.achcorp.sarch.core.domain;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table
public class TagImp implements Tag {

	public TagImp(String text, Tag parent) {
		this.text = text;
		this.parent = parent;
	}

	@Id
	@GeneratedValue
	@Column(name = "ID_TAG")
	private long id;

	@Column
	private String text;

	@ManyToOne(cascade = CascadeType.ALL, targetEntity = TagImp.class)
	private Tag parent;
	@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, targetEntity = TagImp.class)
	private List<Tag> children;

	@ManyToMany(cascade = CascadeType.ALL, targetEntity = DocumentImp.class)
	@JoinTable(name = "document_tags", joinColumns = { @JoinColumn(name = "ID_TAG") }, inverseJoinColumns = { @JoinColumn(name = "ID_DOC") })
	private List<Document> docs;

	public void setText(String text) {
		this.text = text;
	}

	public String getText() {
		return text;
	}

	public void setParent(Tag parent) {
		this.parent = parent;
	}

	public Tag getParent() {
		return parent;
	}

	public void setChildren(List<Tag> children) {
		this.children = children;
	}

	public List<Tag> getChildren() {
		return children;
	}

	public void addChild(Tag child) {
		children.add(child);
	}

	public void removeChild(Tag child) {
		children.remove(child);

	}

	public List<Document> getDocuments() {
		return docs;
	}

	public void setDocuments(List<Document> docs) {
		this.docs = docs;
	}

}
